package com.rabbit.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0.0
 * @ClassName: {@link FanoutRabbitConfig}
 * @Description: TopicRabbitConfig
 * @author: Lanzhou
 * @date: 2021/3/17 9:41
 * @Copyright:2020 All rights reserved.
 */
@Configuration
public class FanoutRabbitConfig {

    public final static String A = "fanout.A";
    public final static String B = "fanout.B";
    public final static String C = "fanout.C";

    @Bean
    public Queue queueA() {
        return new Queue(A, false);
    }

    @Bean
    public Queue queueB() {
        return new Queue(B, false);
    }

    @Bean
    public Queue queueC() {
        return new Queue(C, false);
    }

    @Bean
    public FanoutExchange exchangeFanout() {
        return new FanoutExchange("exchangeFanout");
    }


    /**
     * 绑定规则为, 队列和交换机绑定对应的路由键
     *
     * @return
     */
    @Bean
    public Binding bindingA() {
        return BindingBuilder.bind(queueA()).to(exchangeFanout());
    }

    @Bean
    public Binding bindingB() {
        return BindingBuilder.bind(queueB()).to(exchangeFanout());
    }

    @Bean
    public Binding bindingC() {
        return BindingBuilder.bind(queueC()).to(exchangeFanout());
    }


}
